<?php

declare(strict_types=1);

namespace App\Service;

use App\Model\Coupon as CouponModel;

class Coupon extends BaseService
{
    // 分页列表
    public function list(array $map,int $page = 10)
    {
        return CouponModel::query()->where($map)->orderBy('sort', 'desc')->orderBy('id', 'desc')->paginate($page);
    }

    // 添加
    public function addCoupon($data)
    {
        unset($data['id']);
        $data['created_at'] = date('Y-m-d H:i:s');
        $data['updated_at'] = date('Y-m-d H:i:s');
        return CouponModel::insert($data);
    }

    // 编辑
    public function editCoupon($id, $data)
    {
        $data['updated_at'] = date('Y-m-d H:i:s');
        return CouponModel::query()->where('id', $id)->update($data);
    }

    // 删除
    public function deleteCoupon($id)
    {
        return CouponModel::where('id', $id)->delete();
    }
}
